<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>webSocket</title>

</head>
<body>
<script type="text/javascript">
        var socket;
        if(window.WebSocket){
            socket = new WebSocket("ws://103.12.234.206:8083/ws");
            //socket = new WebSocket("ws://localhost:8890/ws");
            socket.onopen = function (ev) {

                var id = {};
                var ta  = document.getElementById('responseText');
                websocket.send(JSON.stringify(id))
                ta.value = "连接开启";
            }

            socket.onmessage = function (ev) {
                var ta  = document.getElementById('responseText');
                ta.value = ta.value +'\n' +ev.data;

            }





            socket.onclose = function (ev) {
                var ta  = document.getElementById('responseText');
                ta.value = ta.value +'\n' +"连接关闭！";
            }

            socket.onerror = function (ev) {
                console.log("WebSocket连接发生错误");
                console.log(ev)
            }

        }else {
            alert("不支持socket");
        }


        function send(data) {
            socket.send(data);
        }

    </script>
<form onsubmit="return false" >
    <textarea name ="message" style="width:400px;height:200px"></textarea>
    <input type="button" value="发送数据" onclick="send(this.form.message.value)">

    <h3>服务端输出</h3>
    <textarea id="responseText"  style="width:400px;height:200px"></textarea>
    <input type="button" onclick="javasript:document.getElementById('responseText').value=''" value="清空内容">
</form>


</body>
</html>